home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import com.sun.java.accessibility.Accessible;
- import com.sun.java.accessibility.AccessibleContext;
- import com.sun.java.accessibility.AccessibleState;
- import com.sun.java.swing.event.ChangeEvent;
- import com.sun.java.swing.event.ChangeListener;
- import com.sun.java.swing.event.EventListenerList;
- import com.sun.java.swing.plaf.SliderUI;
- import java.awt.Component;
- import java.util.Dictionary;
- import java.util.Enumeration;
- import java.util.Hashtable;
-
- public class JSlider extends JComponent implements SwingConstants, Accessible {
- protected BoundedRangeModel sliderModel;
- protected int majorTickSpacing;
- protected int minorTickSpacing;
- protected boolean snapToTicks;
- private boolean paintTicks;
- private boolean paintLabels;
- private boolean isInverted;
- protected int orientation;
- private Dictionary labelTable;
- protected ChangeListener changeListener;
- protected transient ChangeEvent changeEvent;
- static Class class$com$sun$java$swing$event$ChangeListener;
-
- public JSlider() {
- this(0, 0, 100, 50);
- }
-
- public JSlider(int orientation, int min, int max, int value) {
- this.snapToTicks = true;
- this.paintTicks = false;
- this.paintLabels = false;
- this.isInverted = false;
- this.changeListener = this.createChangeListener();
- this.changeEvent = null;
- this.checkOrientation(orientation);
- this.orientation = orientation;
- this.sliderModel = new DefaultBoundedRangeModel(value, 0, min, max);
- this.sliderModel.addChangeListener(this.changeListener);
- this.updateUI();
- }
-
- public void addChangeListener(ChangeListener l) {
- EventListenerList var10000 = super.listenerList;
- Class var10001 = class$com$sun$java$swing$event$ChangeListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.ChangeListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$com$sun$java$swing$event$ChangeListener = var10001;
- }
-
- var10000.add(var10001, l);
- }
-
- private void checkOrientation(int orientation) {
- switch (orientation) {
- case 0:
- case 1:
- return;
- default:
- throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
- }
- }
-
- protected ChangeListener createChangeListener() {
- return new ModelListener(this);
- }
-
- public Hashtable createStandardLabels(int increment) {
- return this.createStandardLabels(increment, this.getMinimum());
- }
-
- public Hashtable createStandardLabels(int increment, int start) {
- if (start <= this.getMaximum() && start >= this.getMinimum()) {
- Hashtable table = new Hashtable();
-
- for(int labelIndex = start; labelIndex <= this.getMaximum(); labelIndex += increment) {
- table.put(new Integer(labelIndex), new JLabel("" + labelIndex, 0));
- }
-
- return table;
- } else {
- throw new IllegalArgumentException("Slider label start point out of range.");
- }
- }
-
- protected void fireStateChanged() {
- Object[] listeners = super.listenerList.getListenerList();
-
- for(int i = listeners.length - 2; i >= 0; i -= 2) {
- Object var10000 = listeners[i];
- Class var10001 = class$com$sun$java$swing$event$ChangeListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.ChangeListener");
- } catch (ClassNotFoundException var3) {
- throw new NoClassDefFoundError(((Throwable)var3).getMessage());
- }
-
- class$com$sun$java$swing$event$ChangeListener = var10001;
- }
-
- if (var10000 == var10001) {
- if (this.changeEvent == null) {
- this.changeEvent = new ChangeEvent(this);
- }
-
- ((ChangeListener)listeners[i + 1]).stateChanged(this.changeEvent);
- }
- }
-
- }
-
- public AccessibleContext getAccessibleContext() {
- if (super.accessibleContext == null) {
- super.accessibleContext = new AccessibleJSlider(this);
- }
-
- return super.accessibleContext;
- }
-
- public int getExtent() {
- return this.getModel().getExtent();
- }
-
- public boolean getInverted() {
- return this.isInverted;
- }
-
- public Dictionary getLabelTable() {
- return this.labelTable;
- }
-
- public int getMajorTickSpacing() {
- return this.majorTickSpacing;
- }
-
- public int getMaximum() {
- return this.getModel().getMaximum();
- }
-
- public int getMinimum() {
- return this.getModel().getMinimum();
- }
-
- public int getMinorTickSpacing() {
- return this.minorTickSpacing;
- }
-
- public BoundedRangeModel getModel() {
- return this.sliderModel;
- }
-
- public int getOrientation() {
- return this.orientation;
- }
-
- public boolean getPaintLabels() {
- return this.paintLabels;
- }
-
- public boolean getPaintTicks() {
- return this.paintTicks;
- }
-
- public boolean getSnapToTicks() {
- return this.snapToTicks;
- }
-
- public SliderUI getUI() {
- return (SliderUI)super.ui;
- }
-
- public String getUIClassID() {
- return "SliderUI";
- }
-
- public int getValue() {
- return this.getModel().getValue();
- }
-
- public boolean getValueIsAdjusting() {
- return this.getModel().getValueIsAdjusting();
- }
-
- public void removeChangeListener(ChangeListener l) {
- EventListenerList var10000 = super.listenerList;
- Class var10001 = class$com$sun$java$swing$event$ChangeListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.ChangeListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$com$sun$java$swing$event$ChangeListener = var10001;
- }
-
- var10000.remove(var10001, l);
- }
-
- public void setExtent(int extent) {
- this.getModel().setExtent(extent);
- }
-
- public void setInverted(boolean b) {
- boolean oldValue = this.isInverted;
- this.isInverted = b;
- ((JComponent)this).firePropertyChange("inverted", oldValue, this.isInverted);
- }
-
- public void setLabelTable(Dictionary labels) {
- Dictionary oldTable = this.labelTable;
- this.labelTable = labels;
- this.updateLabelUIs();
- ((JComponent)this).firePropertyChange("labelTable", oldTable, this.labelTable);
- }
-
- public void setMajorTickSpacing(int n) {
- int oldValue = this.majorTickSpacing;
- this.majorTickSpacing = n;
- if (this.labelTable == null && this.getMajorTickSpacing() > 0 && this.getPaintLabels()) {
- this.setLabelTable(this.createStandardLabels(this.getMajorTickSpacing()));
- }
-
- ((JComponent)this).firePropertyChange("majorTickSpacing", oldValue, this.majorTickSpacing);
- }
-
- public void setMaximum(int maximum) {
- this.getModel().setMaximum(maximum);
- }
-
- public void setMinimum(int minimum) {
- this.getModel().setMinimum(minimum);
- }
-
- public void setMinorTickSpacing(int n) {
- int oldValue = this.minorTickSpacing;
- this.minorTickSpacing = n;
- ((JComponent)this).firePropertyChange("minorTickSpacing", oldValue, this.minorTickSpacing);
- }
-
- public void setModel(BoundedRangeModel newModel) {
- BoundedRangeModel oldModel = this.getModel();
- if (oldModel != null) {
- oldModel.removeChangeListener(this.changeListener);
- }
-
- this.sliderModel = newModel;
- if (newModel != null) {
- newModel.addChangeListener(this.changeListener);
- if (super.accessibleContext != null) {
- super.accessibleContext.firePropertyChange("AccessibleValue", oldModel == null ? null : new Integer(oldModel.getValue()), newModel == null ? null : new Integer(newModel.getValue()));
- }
- }
-
- ((JComponent)this).firePropertyChange("model", oldModel, this.sliderModel);
- }
-
- public void setOrientation(int orientation) {
- this.checkOrientation(orientation);
- this.orientation = orientation;
- ((JComponent)this).firePropertyChange("orientation", orientation, orientation);
- if (orientation != orientation && super.accessibleContext != null) {
- super.accessibleContext.firePropertyChange("AccessibleState", orientation == 1 ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL, orientation == 1 ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL);
- }
-
- }
-
- public void setPaintLabels(boolean b) {
- boolean oldValue = this.paintLabels;
- this.paintLabels = b;
- if (this.labelTable == null && this.getMajorTickSpacing() > 0) {
- this.setLabelTable(this.createStandardLabels(this.getMajorTickSpacing()));
- }
-
- ((JComponent)this).firePropertyChange("paintLabels", oldValue, this.paintLabels);
- }
-
- public void setPaintTicks(boolean b) {
- boolean oldValue = this.paintTicks;
- this.paintTicks = b;
- ((JComponent)this).firePropertyChange("paintTicks", oldValue, this.paintTicks);
- }
-
- public void setSnapToTicks(boolean b) {
- boolean oldValue = this.snapToTicks;
- this.snapToTicks = b;
- ((JComponent)this).firePropertyChange("snapToTicks", oldValue, this.snapToTicks);
- }
-
- public void setUI(SliderUI ui) {
- super.setUI(ui);
- }
-
- public void setValue(int n) {
- BoundedRangeModel m = this.getModel();
- int oldValue = m.getValue();
- m.setValue(n);
- if (super.accessibleContext != null) {
- super.accessibleContext.firePropertyChange("AccessibleValue", new Integer(oldValue), new Integer(m.getValue()));
- }
-
- }
-
- public void setValueIsAdjusting(boolean b) {
- BoundedRangeModel m = this.getModel();
- boolean oldValue = m.getValueIsAdjusting();
- m.setValueIsAdjusting(b);
- if (oldValue != b && super.accessibleContext != null) {
- super.accessibleContext.firePropertyChange("AccessibleState", oldValue ? AccessibleState.BUSY : null, b ? AccessibleState.BUSY : null);
- }
-
- }
-
- public String toString() {
- String containerString = "";
- if (!((Component)this).isEnabled() && !((Component)this).isVisible()) {
- containerString = "(not Enabled, not Visible)";
- } else if (!((Component)this).isEnabled()) {
- containerString = "(not Enabled)";
- } else if (!((Component)this).isVisible()) {
- containerString = "(not Visible)";
- }
-
- String sliderString = containerString + (this.getOrientation() == 1 ? "vertical" : "horizontal") + ", " + "value=" + this.getValue() + ", " + "adj=" + this.getValueIsAdjusting() + ", " + "min=" + this.getMinimum() + ", " + "max=" + this.getMaximum() + ", " + "majorTickSpacing=" + this.getMajorTickSpacing() + ", " + "minorTickSpacing=" + this.getMinorTickSpacing() + ", " + "snapToTicks=" + this.getSnapToTicks() + ", " + "isInverted=" + this.getInverted() + ", " + "paintLabels=" + this.getPaintLabels() + ", " + "paintTicks=" + this.getPaintTicks();
- return this.getClass().getName() + "[" + sliderString + "]";
- }
-
- protected void updateLabelUIs() {
- if (this.getLabelTable() != null) {
- Enumeration labels = this.getLabelTable().keys();
-
- while(labels.hasMoreElements()) {
- Object value = this.getLabelTable().get(labels.nextElement());
- if (value instanceof JComponent) {
- JComponent component = (JComponent)value;
- component.updateUI();
- ((Component)component).setSize(component.getPreferredSize());
- }
- }
-
- }
- }
-
- public void updateUI() {
- this.updateLabelUIs();
- this.setUI((SliderUI)UIManager.getUI(this));
- }
- }
-